$(function(){
    //响应式设置
    $(function(){
        function fullwidth(){
            if($('body').width() >= 1000){
                $('html').css('font-size',100 + 'px');
                return ;
            }
            var scale = $('body').width() / 1000;
            $('html').css('font-size',scale * 100 + 'px' );
        }
        fullwidth();
        $(window).resize(function(){
            fullwidth();
        })
    });

//窗口大小改变时
    $(window).resize(function() {
        $('#menu_bar').css('display','none');
        $('.order_one li:nth-child(1)').hover(function(){
            $('#menu_bar').css('display','block');
        });
        $('#conleft').css('display','none');
        $('#conright').css('display','none');
    });

    //轮播图效果
    var lis = $('.list li');
    var dos = $('.count li');
    var p = 0;
    function show(a){
        lis.eq(a).css('display','block').animate({opacity:0.8},800).siblings().css('display','none').animate({opacity:0.3},500);
        dos.css('cursor','pointer').eq(a).addClass('on').siblings(a).removeClass('on');
    }
    /*手动效果*/
    dos.each(function(index){
        $(this).mouseover(function(){
            clearInterval(timer);
            show(index);
        }).mouseout(function(){
            p = index;
            autoplay();
        })
    });
    lis.mouseover(function(){
        clearInterval(timer);
    }).mouseout(function(){
        autoplay();
    });
    //自动播放效果
    function autoplay(){
        timer = setInterval(function(){
            p++;
            if(p>=lis.length){
                p = 0;
            }
            show(p);
        },2000)
    }
    autoplay();


    //监听滚轮事件
    $(window).scroll(function(){
        var top = $(window).scrollTop();
        //var tt = $('body').scrollTop();
        console.log(top);
        if(top >= 430){
            $('#conleft').fadeIn("slow");
             $('#conright').fadeIn("slow");
            if(top >= 1000&&top <= 4000){
                $('#conleft div:nth-child(2)').css('background-position','0 -3.05rem');    //效果没出来
                $('#conleft div:nth-child(3)').css('background-position','-0.67rem -3.82rem');
            }else if(top >= 4000&&top <= 7400 || top >= 10873&&top <= 14273){
                $('#conleft div:nth-child(2)').css('background-position','-0.67rem -3.05rem');
                $('#conleft div:nth-child(3)').css('background-position','0 -3.82rem');
            }else {
                $('#conleft div:nth-child(2)').css('background-position','-0.67rem -3.05rem');
                $('#conleft div:nth-child(3)').css('background-position','-0.67rem -3.82rem');
            }
        }else{
            $('#conleft').fadeOut("slow");
            $('#conright').fadeOut("slow");
        }
    });

    $('#conleft div:nth-child(2)').click(function(){
        $('#conleft div:nth-child(2)').css('background-position','0 -3.05rem');
        $('body').animate({scrollTop: '1000px'}, 200);
    });
    $('#conleft div:nth-child(3)').click(function(){
        $('#conleft div:nth-child(3)').css('background-position','0 -3.82rem');
        $('body').animate({scrollTop: '4200px'}, 200);
    });

    //回到顶部
    $('#conright section').click(function(){$('body').animate({scrollTop: '0px'}, 800);});
});
